use actix_web::{
    http::{header::ContentType, StatusCode},
    HttpResponse,
};

use serde_json::{json, Value};

pub fn get_data_response(data: Value) -> HttpResponse {
    HttpResponse::Ok()
        .content_type(ContentType::json())
        .json(json!({
          "success": true,
          "payload": data,
        }))
}

pub fn get_error_response(
    http_status: StatusCode,
    error: &str,
    message: &str,
    path: &str,
) -> HttpResponse {
    HttpResponse::build(http_status)
        .content_type(ContentType::json())
        .json(get_error_response_data(http_status, error, message, path))
}

pub fn get_error_response_data(
    http_status: StatusCode,
    error: &str,
    message: &str,
    path: &str,
) -> Value {
    json!({
      "success": false,
      // "timestamp": crate::shared::date_helper::get_timestamp(),
      "status": http_status.as_u16(),
      "error": error,
      "message": message,
      "path": path,
    })
}
